﻿#region License
// (c) Garry McGlennon 2009
// 
// UnitTestEx is made available under the Microsoft Public License (Ms-PL)
// Code is provided as is and with no warrenty – Use at your own risk
// View the project and the latest code at http://codeplex.com/UnitTestEx/
// 
// All other rights reserved.
// 
// blog: www.dotNetProfessional.com/blog/
#endregion
using System;
using System.Collections;
using System.Collections.Generic;

namespace dnp.UnitTestEx
{
    /// <summary>
    /// Converts an IEnumberable collection into any type of IList collection. This is mainly used to convert the result of Linq queries into custom collections.
    /// </summary>
    public static class LinqEx
    {
        public static TDestination ToList<TSource, TDestination>(this IEnumerable<TSource> source, TDestination destination) where TDestination : IList
        {
            if (destination == null)
                throw new ArgumentException("TDestination must be an instance of a IList collection");

            foreach (var item in source)
                destination.Add(item);

            return destination;
        }
    }
}
